# SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

cmake_minimum_required(VERSION 3.9.5)

if (NOT DEFINED VERSION)
    set(VERSION 1.0.0)
endif ()
configure_file(../src/environments.h.in environments.h @ONLY)
# set(LINK_LIBS
#     Qt5::Core
#     Qt5::Widgets
#     Qt5::Gui
#     Qt5::Multimedia
#     Qt5::Test
#     ${DtkWidget_LIBRARIES}
#     ${DtkCore_LIBRARIES}
#     ${DtkGUI_LIBRARIES}
# )
#可访问private
ADD_COMPILE_OPTIONS(-fno-access-control)
ADD_COMPILE_OPTIONS(-fno-inline)
set (PROJECT_NAME_TEST deepin-lianliankan-test)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
#set(CMAKE_CXX_FLAGS "-g -Wall")
#编译生成覆盖环境
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
#添加-fno-inline编译选项，禁止内联，能获取到函数地址，可以对内联函数进行打桩
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-inline")
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "sw_64")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mieee")
endif ()

set(CMAKE_SAFETYTEST "${CMAKE_SAFETYTEST_ARG}")
if(CMAKE_SAFETYTEST STREQUAL "")
    set(CMAKE_SAFETYTEST "CMAKE_SAFETYTEST_ARG_OFF")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${CMAKE_SAFETYTEST}")
if(CMAKE_SAFETYTEST STREQUAL "CMAKE_SAFETYTEST_ARG_ON")
  #安全测试选项
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=undefined,address -O2")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=undefined,address -O2")
endif()

# Find the library
find_package(PkgConfig REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}Test REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Multimedia REQUIRED)
find_package(Dtk${DTK_VERSION}Core REQUIRED)
find_package(Dtk${DTK_VERSION}Widget REQUIRED)
find_package(Dtk${DTK_VERSION}Gui REQUIRED)
add_definitions(${Qt5Test_DEFINITIONS})
FILE(GLOB allSource
     ../src/source/closewindowdialog.cpp
     ../src/source/gameblureffectwidget.cpp
     ../src/source/gamebutton.cpp
     ../src/source/gamecontrol.cpp
     ../src/source/gamelinescene.cpp
     ../src/source/closewindowdialog.cpp
     ../src/source/gameoverblureffectwidget.cpp
     ../src/source/gamepage.cpp
     ../src/source/gameprogressbar.cpp
     ../src/source/lianliankanapplication.cpp
     ../src/source/mainpage.cpp
     ../src/source/mainwindow.cpp
     ../src/source/shadowlabel.cpp
     ../src/source/utils.cpp
)
FILE(GLOB qrcFiles
    ../src/resources.qrc
)


# 5. 头文件
# 5.1. 定义函数，用于递归添加头文件
function(include_sub_directories_recursively root_dir)
    if (IS_DIRECTORY ${root_dir})               # 当前路径是一个目录吗，是的话就加入到包含目录
        #message("include dir: " ${root_dir})
        include_directories(${root_dir})
    endif()

    file(GLOB ALL_SUB RELATIVE ${root_dir} ${root_dir}/*) # 获得当前目录下的所有文件，让如ALL_SUB列表中
    foreach(sub ${ALL_SUB})
        if (IS_DIRECTORY ${root_dir}/${sub})
            include_sub_directories_recursively(${root_dir}/${sub}) # 对子目录递归调用，包含
        endif()
    endforeach()
endfunction()

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_sub_directories_recursively("${CMAKE_CURRENT_SOURCE_DIR}/../src/source")
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

FILE(GLOB allTestSource
src/*.cpp
)
include_directories(src)


add_executable (${PROJECT_NAME_TEST} ${allSource} ${APP_QRC_FILES}  ${APP_QM_FILES} ${qrcFiles}   ${allTestSource})

target_link_libraries(${PROJECT_NAME_TEST}
    ${LINK_LIBS}
    ${GTEST_LIBRARIES}
    ${GTEST_MAIN_LIBRARIES}
    pthread -ldl -fPIC
    Dtk${DTK_VERSION}::Core
    Dtk${DTK_VERSION}::Gui
    Dtk${DTK_VERSION}::Widget
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Multimedia
)

